const pageAction = [
  {
    id: 'pageServer.go',
    name: '切换路由(上一个/下一个)',
    type: 'page',
    exec: (app, param) => {
      let routeParam = 0
      ;(param.key == 'left' || param.key == 'up') && (routeParam = -1)
      ;(param.key == 'right' || param.key == 'down') && (routeParam = 1)
      app.pageServer.go(routeParam)
    }
  },
  {
    id: 'pageServer.goTo',
    name: '切换路由(第几个)',
    type: 'page',
    exec: (app, param) => {
      const numChar = {
        一: 1,
        二: 2,
        三: 3,
        四: 4,
        五: 5,
        六: 6,
        七: 7,
        八: 8,
        九: 9,
        十: 10
      }
      const routerLength = app.pageServer.getCurrentContext().$router.options.routes.length - 2
      let num = param[0] - 0
      if (isNaN(num)) {
        num = numChar[param[0]] || 1
        if(num > routerLength) return
      }
      if (!isNaN(num)) {
        if(num > routerLength) return
      }
      app.pageServer.goTo(num)
    }
  },
  {
    id: 'pageServer.goByNameText',
    name: '根据路由显示名称切换路由',
    type: 'page',
    exec: (app, param) => {
      let nameText = param[3],
        newPath = param[2]
      const currentPath = app.pageServer.getCurrentContext().$route.path
      const currentRouterOption = app.pageServer.getCurrentContext().$router.options.routes
      let iscurrentName = false
      currentRouterOption.forEach(element => {
        if(element.path == currentPath){
          if(element.nameText == nameText){
            iscurrentName = true
            return
          }
        }
      });
      if(iscurrentName) return
      if (!newPath || newPath !== currentPath) {
        app.pageServer.goByNameText(nameText)
      }
    }
  }
]
export default pageAction
